#ifndef __SYS_H__
#define __SYS_H__
#include "t5los8051.h"

//类型重定义
typedef unsigned char   u8;
typedef unsigned short  u16;
typedef unsigned long   u32;
typedef signed char     s8;
typedef signed short    s16;
typedef signed long     s32;

//看门狗宏定义
#define	WDT_ON()				MUX_SEL|=0x02		//开启看门狗
#define	WDT_OFF()				MUX_SEL&=0xFD		//关闭看门狗
#define	WDT_RST()				MUX_SEL|=0x01		//喂狗

//系统主频和1ms定时数值定义
#define FOSC     				206438400UL
#define T1MS    				(65536-FOSC/12/1000)

#define TOUCH_EVENT_ADDR                   0x5000 /* 模式控制按键事件地址 */
#define TOUCH_EVENT_MODE_ICONS_ADDR        0x50F0 /* 可变图标地址 */
#define TOUCH_WHOLE_CONTROL_VALUE_ADDR     0x50F1 /* 整体控制等级值地址 */
#define TOUCH_LED01_CONTROL_VALUE_ADDR     0x5100 /* 灯具 01 等级值地址 */
#define TOUCH_LED02_CONTROL_VALUE_ADDR     0x5101 /* 灯具 02 等级值地址 */
#define TOUCH_LED03_CONTROL_VALUE_ADDR     0x5102 /* 灯具 03 等级值地址 */

#define TOUCH_EVENT_SMART_MDOE             0x01
#define TOUCH_EVENT_MANUAL_MDOE            0x02
#define TOUCH_EVENT_PLAY_MDOE              0x03
#define TOUCH_EVENT_STAND_MDOE             0x04
#define TOUCH_EVENT_SLEEP_MDOE             0x05
#define TOUCH_EVENT_WEAKUP_MDOE            0x06

#define TOUCH_EVENT_WHOLE_CONTROL          0xff
#define TOUCH_EVENT_LED01_CONTROL          0x80
#define TOUCH_EVENT_LED02_CONTROL          0x81
#define TOUCH_EVENT_LED03_CONTROL          0x82

// 函数声明
void sys_init(void);
void sys_delay_about_ms(u16 ms);
void sys_delay_about_us(u8 us);
void sys_delay_ms(u16 ms);
void sys_read_vp(u16 addr,u8* buf,u16 len);
void sys_write_vp(u16 addr,u8* buf,u16 len);
void sys_write_vp_u32(u16 addr,u32 data);
void sys_write_vp_u16(u16 addr,u16 data);

int can_init(u32 baud);
void can_write(u16 id, u8 *buffer, u8 len);

void control_lamp_with_mode(u16 mode);
void control_whole_lamp_with_level(u16 level);
void control_one_lamp_with_level(u16 addr, u16 level);

void set_event_status(u16 event);
u16 get_event_status(void);
void clear_event_status(void);
#endif


